package platform.standard.input;

import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.util.Queue;
import java.util.concurrent.ConcurrentLinkedQueue;

import engine.input.KeyInfo;
import engine.input.KeyQueue_I;

public class AwtKeyQueue implements KeyListener, KeyQueue_I {
	public AwtKeyQueue() {
		_KeyQueue = new ConcurrentLinkedQueue<KeyInfo>();
	}
	
	private Queue<KeyInfo> _KeyQueue;
	
	// KeyListener -------------------------------------------------------------
	
	@Override
	public void keyPressed(KeyEvent arg0) {
		push(arg0.getKeyCode(), true, arg0.getWhen());
	}

	@Override
	public void keyReleased(KeyEvent arg0) {
		push(arg0.getKeyCode(), false, arg0.getWhen());
	}

	@Override
	public void keyTyped(KeyEvent arg0) {
		// Not sure if we need this method?
	}
	
	// KeyQueue_I --------------------------------------------------------------
	
	@Override
	public void push(int vKey, boolean pressed, long timeStamp) {
		_KeyQueue.offer(new KeyInfo(vKey, pressed, timeStamp));
	}

	@Override
	public KeyInfo pop() {
		return _KeyQueue.poll();
	}

	@Override
	public void clear() {
		_KeyQueue.clear();
	}
}
